﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ProgShortcut
{
    public partial class frmIcon : Form
    {
        public static bool Showing = false;
        Shortcut info;
        public frmIcon()
        {
            InitializeComponent();
            info = null;
        }
        public frmIcon(Shortcut d)
        {
            InitializeComponent();
            info = d;
            info.Change += info_Change;
            affiche();
            Left = System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Width - Width;
            Top = System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Height - Height - 32;
            Showing = true;
            this.ShowInTaskbar = false;
        }
        private void info_Change(object sender, ChangeEventArgs e)
        {
            affiche();
        }
        private void affiche()
        {
            this.Controls.Clear();
            ToolTip toolTip = new ToolTip();
            toolTip.AutoPopDelay = 0;
            toolTip.InitialDelay = 0;
            toolTip.ReshowDelay = 0;
            toolTip.ShowAlways = true;

            int index = 0;
            foreach (Categorie c in info.GetCategories())
            {
                foreach(Fichier f in c.getFile())
                {
                    PictureBox pb = new PictureBox();
                    pb.Image = f.Icon;
                    this.Controls.Add(pb);
                    pb.Tag = f;
                    pb.Location = new System.Drawing.Point((index % 9) * 32, (index / 9) * 32);
                    pb.Click += pb_Click;
                    pb.Visible = true;
                    pb.Size = new System.Drawing.Size(32, 32);
                    toolTip.SetToolTip(pb, f.Nom);
                    index++;
                }
            }
            this.Height = (index / 9 + (index % 9 == 0 ? 0 : 1)) * 32 + 38;
            this.Width = 305;
            Left = System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Width - Width;
            Top = System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Height - Height - 32;
        }
        private void pb_Click(object sender, EventArgs e)
        {
            ((Fichier)((PictureBox)sender).Tag).Action();
        }
        private void frmIcon_FormClosing(object sender, FormClosingEventArgs e)
        {
            Showing = false;
        }
    }
}